home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / nt_dsp1.lzh / NT_DSP1.MSA / CODEC / LINLOG.ASM next >
Encoding:
Assembly Source File  |  1989-01-24  |  4.9 KB  |  151 lines

  1. linlog    ident    1,1
  2. ;
  3. ; This program, originally available on the Motorola DSP bulletin board,
  4. ; is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  5. ; Operation, 6501 William Cannon Drive, West, Austin, Texas  78735-8598.
  6. ;
  7. ;
  8. ; Linear PCM to Companded CODEC Data Conversion Macros
  9. ;
  10. ; These macros convert 13 bit, linear fractional data into 8 bit companded
  11. ; data suitable for transmission to CODEC D/A converters used in
  12. ; telecommunications applications.  Four companded formats are
  13. ; supported for the Motorola MC14400 CODEC series and similar devices.
  14. ;
  15. ; Macro Calls:        linsm -    linear to sign magnitude conversion
  16. ;                with mu-law companding.
  17. ;            linmu -    linear to mu-law companded conversion
  18. ;                without zero code suppression.
  19. ;            lind3d4 - linear to mu-law companded conversion
  20. ;                with D3/D4 format zero code suppression.
  21. ;            linal -    linear to a-law companded conversion
  22. ;                with CCITT (G7.12) format.
  23. ;
  24. ;            No macro arguments are required.  However, these
  25. ;               macros assume that the scaling modes are off
  26. ;            (S1=0, S0=0).
  27. ;
  28. ; Input data is a 56 bit number in accumulator a.  Although any 56 bit
  29. ; number may be used, the 13 bit linear fraction is assumed to be in
  30. ; the most significant bits of a1.  Values outside this fractional range
  31. ; are automatically converted to a maximum positive or negative companded
  32. ; value (dynamic range limiting).
  33. ;
  34. ; Output data is in the 8 most significant bits of a1.  The 16 LSB's
  35. ; of a1 are zero.
  36. ;
  37. ;  -------------------------------------------------------
  38. ; | Sign |    Chord Number    |       Step Number         |
  39. ; | Bit  |                    |                           |
  40. ; |__23__|__22_____21_____20__|__19_____18_____17_____16__|
  41. ;
  42. ; Alters Data ALU Registers
  43. ;       x1      x0
  44. ;       a2      a1      a0      a
  45. ;       b2      b1      b0      b
  46. ;
  47. ; Alters Address Registers
  48. ;       r0
  49. ;
  50. ; Alters Program Control Registers
  51. ;       pc      sr
  52. ;
  53. ; Uses 0 locations on System Stack
  54. ;
  55. ; Latest Revision - August 17, 1988
  56. ; Tested and verified - August 17, 1988
  57. ;
  58. ; linsm - linear to sign magnitude conversion
  59. ;
  60. linsm    macro
  61. _bias    equ    $008400            ;absolute bias = 33
  62. ;
  63.     tfr    a,b    a,a        ;save input sign, limit input data
  64.     abs    a    #_bias,x0    ;form input magnitude, get bias
  65.     add    x0,a    #7,r0        ;add bias to magnitude, get chord bar
  66.     move        a,a        ;limit again
  67.     tst    a            ;set CCR for norm instruction
  68.     rep    #7            ;find chord number by normalizing
  69.     norm    r0,a            ; biased magnitude to get step number
  70.     asl    a            ;isolate step number
  71.     asl    a    b,b        ;limit input again
  72.     neg    b    r0,a2        ;invert sign bit, get chord number
  73.     asr    a            ;combine chord and step
  74.     asr    a
  75.     asr    a
  76.     asl    b            ;get sign bit
  77.     ror    a    #<$ff,x0    ;combine sign, chord and step
  78.     and    x0,a            ;clear 16 LSB's
  79.     endm
  80. ;
  81. ; linmu - linear to mu-law conversion
  82. ;
  83. linmu    macro
  84. _bias    equ    $008400            ;absolute bias = 33
  85. ;
  86.     tfr    a,b    a,a        ;save input sign, limit input data
  87.     abs    a    #_bias,x0    ;form input magnitude, get bias
  88.     add    x0,a    #7,r0        ;add bias to magnitude, get chord bar
  89.     move        a,a        ;limit again
  90.     tst    a            ;set CCR for norm instruction
  91.     rep    #7            ;find chord number by normalizing
  92.     norm    r0,a            ; biased magnitude to get step number
  93.     asl    a            ;isolate step number
  94.     asl    a    b,b        ;limit input again
  95.     neg    b    r0,a2        ;invert sign bit, get chord number
  96.     asr    a            ;combine chord and step
  97.     asr    a
  98.     asr    a
  99.     not    a            ;invert 7 LSB's for mu-law
  100.     asl    b            ;get sign bit
  101.     ror    a    #<$ff,x0    ;combine sign, chord and step
  102.     and    x0,a            ;clear 16 LSB's
  103.     endm
  104. ;
  105. ; lind3d4 - linear to mu-law conversion with zero code suppression
  106. ;
  107. lind3d4    macro
  108. _bias    equ    $008400            ;absolute bias = 33
  109. ;
  110.     tfr    a,b    a,a        ;save input sign, limit input data
  111.     abs    a    #_bias,x0    ;form input magnitude, get bias
  112.     add    x0,a    #7,r0        ;add bias to magnitude, get chord bar
  113.     move        a,a        ;limit again
  114.     tst    a            ;set CCR for norm instruction
  115.     rep    #7            ;find chord number by normalizing
  116.     norm    r0,a            ; biased magnitude to get step number
  117.     asl    a            ;isolate step number
  118.     asl    a    b,b        ;limit input again
  119.     neg    b    r0,a2        ;invert sign bit, get chord number
  120.     asr    a            ;combine chord and step
  121.     asr    a
  122.     asr    a
  123.     not    a            ;invert 7 LSB's for mu-law
  124.     asl    b            ;get sign bit
  125.     ror    a    #<$ff,x0    ;combine sign, chord and step
  126.     and    x0,a    #<$02,x0    ;clear 16 LSB's
  127.     teq    x0,a            ;suppress zero code
  128.     endm
  129. ;
  130. ; linal - linear to a-law conversion
  131. ;
  132. linal    macro
  133.     tfr    a,b    a,a        ;save input sign, limit input data
  134.     move        #1,a0        ;force to non-zero value
  135.     abs    a    #7,r0        ;form input magnitude, get chord bar
  136.     rep    #6            ;find chord number by normalizing
  137.     norm    r0,a            ; magnitude to get step number
  138.     jnr    <_ok            ;jump if normalized
  139.     move        (r0)-        ;adjust for chord zero
  140. _ok    asl    a            ;isolate step number
  141.     asl    a    b,b        ;limit input again
  142.     neg    b    r0,a2        ;invert sign bit, get chord number
  143.     asr    a            ;combine chord and step
  144.     asr    a
  145.     asr    a
  146.     asl    b            ;get sign bit
  147.     ror    a    #<$ff,x0    ;combine sign, chord and step
  148.     and    x0,a    #<$55,x0    ;clear 16 LSB's
  149.     eor    x0,a            ;invert odd bits for a-law
  150.     endm
  151.